// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CameraPoseEstimationAgentMessage.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Microsoft.Robotics.Vision.Runtime.GroundTruthExtraction
{
    using System;
    using System.Drawing;
    using System.Runtime.Serialization;

    using Microsoft.Robotics.Numerics;
    using Microsoft.Robotics.Runtime;
    using Microsoft.Robotics.Vision;

    /// <summary>
    /// The CameraPoseEstimationAgentMessage class represents ground truth pose of the robot used for metrics.
    /// </summary>
    [DataContract]
    public class CameraPoseEstimationAgentMessage : AgentMessage
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="CameraPoseEstimationAgentMessage" /> class
        /// </summary>
        /// <param name="originatingTime">The camera pose estimation message creation time.</param>        
        /// <param name="translations">Translations estimated by the planar pose estimator</param>
        /// <param name="rotations">Rotations estimated by the planar pose estimator</param>
        /// <param name="cameraPose">Camera pose in landmark coordinates after fixing for landmark tilt</param>
        /// <param name="landmarkPoint">Landmark point against which this camera pose was estimated</param>
        public CameraPoseEstimationAgentMessage(
            long originatingTime,
            Vector3? translations = null,
            Vector3? rotations = null,
            Pose2D? cameraPose = null,
            Landmark landmarkPoint = null)
            : base(originatingTime)
        {
            if (translations == null)
            {
                this.Translations = new Vector3(double.NaN, double.NaN, double.NaN);
            }
            else
            {
                this.Translations = translations.Value;
            }

            if (rotations == null)
            {
                this.Rotations = new Vector3(double.NaN, double.NaN, double.NaN);
            }
            else
            {
                this.Rotations = rotations.Value;
            }

            this.CameraPose = cameraPose;
            this.Landmark = landmarkPoint;
        }

        /// <summary>
        /// Gets the Translations of the Landmark with respect to the Camera.
        /// </summary>
        [DataMember]
        public Vector3 Translations { get; private set; }

        /// <summary>
        /// Gets the Rotations of the Landmark with respect to the Camera.
        /// </summary>
        [DataMember]
        public Vector3 Rotations { get; private set; }

        /// <summary>
        /// Gets the camera pose in landmark centered coordinates after fixing for any tilt in the landmark.
        /// To get the camera pose in absolute coordinates, add the landmark pose to the camera pose.
        /// </summary>
        [DataMember]
        public Pose2D? CameraPose { get; private set; }

        /// <summary>
        /// Gets the Landmark against which the pose was estimated.
        /// </summary>
        [DataMember]
        public Landmark Landmark { get; private set; }
    }
}
